package logic

import (
	"context"
	"errors"
	"smart-health-platforms/pkg"
	"user_srv/internal/dao"
	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddFaseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddFaseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddFaseLogic {
	return &AddFaseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 添加人脸
func (l *AddFaseLogic) AddFase(in *user.AddFaseRequest) (*user.AddFaseResponse, error) {
	if in.UserId <= 0 {
		pkg.Error("用户ID不能为空")
		return nil, errors.New("用户ID不能为空")
	}
	if in.Image == "" {
		pkg.Error("图片路径不能为空")
		return nil, errors.New("图片路径不能为空")
	}

	// 2. 调用DAO层执行添加（内部已包含查重逻辑）
	if err := dao.AddFaseByUserId(int32(in.UserId), in.Image); err != nil {
		return nil, err
	}
	return &user.AddFaseResponse{
		Msg: "添加成功",
	}, nil
}
